<?php
	namespace Home\Controller;
	//use Think\Controller;
	/**
	 * 前台首页展示
	 */
	class IndexController extends BaseController {
	    public function index(){
			// 获取轮播图
			$slider = D('Admin/Slider');
			$sliderData = $slider->getData();
			
			// 获取推荐文章
			$article = D('Article');
			$articleData = $article->getRecommendArticle();
			
			// 获取留言个数
			//var_dump($articleData);die;
			// 分配变量
			
			$this->assign('visitor', $this->visitor);
			$this->assign('cateNum', count($this->headerData));
			$this->assign('cateData', $this->headerData);
			$this->assign('mostHits', $this->mostHits);
			$this->assign('AllCate', $this->AllCate);
			
			$this->assign('sliderData', $sliderData);
			$this->assign('articleData', $articleData);
			//var_dump($cateData);die;
	        // 展示模板
	        $this->display();
	    }

	    /**
	     * 定义一个获取文章的api
	     */
	    public function getApi($code = '') {
	    	if($code == '12345') {
	    		// 获取推荐文章
				$article = D('Article');
				$articleData = $article->getRecommendArticle();
				//return $this -> response($articleData, 'json');
				header('Content-Type: application/json; charset=utf-8');
				return json_encode($articleData,true);			
	    	}else {
	    		$data = ['data'=>'false'];
	    		//header('Content-Type: application/json; charset=utf-8');
	    		echo json_encode($data);
	    	}
	    }
	}